﻿@page "/pemission/list"
@using Messhall.UI.Permission.Model
@using Messhall.UI.Permission.Model.Permissions
@using Messhall.UI.Permission.Pages.Users
@using Microsoft.AspNetCore.Components
@using Google.Protobuf.WellKnownTypes

<p>
    <b>右侧分割线 <code>style="border-right: 1px solid #e6e6e6;"</code></b>
</p>

<div class="row g-3">
    <div class="col-12 col-sm-4" style="height: 100% !important;width:250px">
        <Menu Items="@IconSideMenuItems" OnClick="(e) => OnMenuItemClick(e)" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;"/>
    </div>
    <div class="col-12 col-sm-6 h-100">
        <ul class="ul-demo">
            <li><code>ValidateForm</code> 组件支持异步设置 <code>Model</code> 值</li>
            <li>通过设置提交按钮 <code>Button</code> 属性 <code>IsAsync</code> 值，设置异步提交表单</li>
        </ul>
        <ValidateForm Model="_permissionModel" OnValidSubmit="SubmitAsync">
            <EditorForm Model="_permissionModel" AutoGenerateAllItem="false">
                <FieldItems>
                    <EditorItem @bind-Field="@context.Name"/>
                    <EditorItem @bind-Field="@context.Icon">
                        <EditTemplate Context="value">
                            <div class="col-12 col-sm-6">
                                <BootstrapInput placeholder="" @bind-Value="@context.Icon" DisplayText="图标" ShowLabel="true"/>
                            </div>
                            <div class="col-12 col-sm-6">
                                <i class="@context.Icon" style="margin-top: 38px;"></i>
                            </div>
                        </EditTemplate>
                    </EditorItem>
                    <EditorItem @bind-Field="@context.Url"/>
                    <EditorItem @bind-Field="@context.Remark">
                        <EditTemplate Context="value">
                            <div class="col-12 col-sm-12">
                                <Textarea @bind-Value="context.Remark" placeholder="请输入 ..." rows="4"></Textarea>
                            </div>
                            <div class="col-12 col-sm-6">
                            </div>
                        </EditTemplate>
                    </EditorItem>

                    <EditorItem @bind-Field="@context.Authority">
                        <EditTemplate Context="value">
                            <div class="col-12 col-sm-12">
                                <label class="form-label">权限按钮</label>
                                <Card>
                                    <CardBody>
                                        <div class="row g-3">
                                            @foreach (var item in context.Authority)
                                            {
                                                <div class="col-6 col-sm-4 col-md-3 col-lg-auto">
                                                    <Button OnClick="() => ModifyAuthority(item)" Size="Size.ExtraSmall" Color="Color.Secondary">@item.Name</Button>
                                                </div>
                                            }
                                            <div class="col-6 col-sm-4 col-md-3 col-lg-auto">
                                                <Button OnClick="ShowAuthorityModal" Size="Size.ExtraSmall" Color="Color.Primary" Icon="fa fa-fw fa-plus-circle">添加</Button>
                                            </div>
                                        </div>
                                    </CardBody>
                                </Card>
                            </div>
                            <div class="col-12 col-sm-6">
                            </div>
                        </EditTemplate>
                    </EditorItem>

                </FieldItems>
                <Buttons>
                    <Button ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="提交"/>
                    <PopConfirmButton Placement="Placement.Top" Color="Color.Danger" ConfirmIcon="fa fa-exclamation-triangle text-danger"
                                      ConfirmButtonColor="Color.Danger" Text="删除" Content="确定删除数据吗？" Icon="fa fa-remove" IsAsync="true"
                                      OnConfirm="RemoveAsync"/>
                </Buttons>
            </EditorForm>
        </ValidateForm>
    </div>
</div>

<Modal @ref="_smailModal" IsCentered>
    <ModalDialog Size="Size.Small" Title="权限" ShowCloseButton="false">
        <BodyTemplate>
            <ValidateForm TModel="AuthorityModel" Model="@_authorityModel" OnValidSubmit="@SubmitAuthority">
                <div class="row g-3">
                    <div class="col-12">
                        <BootstrapInput @bind-Value="@_authorityModel.Name"/>
                    </div>
                    <div class="col-12">
                        <BootstrapInput @bind-Value="@_authorityModel.Code"/>
                    </div>
                    <div class="col-12">
                        <Button ButtonType="ButtonType.Submit" Icon="fa fa-fw fa-save" Text="保存" IsAsync="true"/>
                        <Button OnClick="RemoveAuthority" Color="Color.Danger" Icon="fa fa-fw fa-remove" Text="删除" IsAsync="true"/>
                    </div>
                </div>
            </ValidateForm>
        </BodyTemplate>
    </ModalDialog>
</Modal>